package com.sxzjrj.test

import org.apache.spark.{SparkConf, SparkContext}

object MyWordCount {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf()
    conf.setMaster("local")
      .setAppName("我的第一个spark程序")

    val sc = new SparkContext(conf)

    val file = sc.textFile("e:\\hello.txt")

    val word = file.flatMap(_.split(" "))
    val wordOne = word.map((_, 1))
    val wordCount = wordOne.reduceByKey(_+_)
    val sortRdd = wordCount.sortBy(tuple => tuple._2, false)
    sortRdd.saveAsTextFile("e:\\outrdd")

    sc.stop()
  }
}
